package com.xinhe.web.controller;

import com.querydsl.core.QueryResults;
import com.xinhe.web.common.Result;
import com.xinhe.web.response.OrderReturnByUserView;
import com.xinhe.web.response.OrderReturnDetailView;
import com.xinhe.web.response.OrderReturnView;
import com.xinhe.web.service.OrderReturnService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

@Api(value = "订单退款", tags = {"订单退款"})
@RestController
@RequestMapping(value = {"/orderReturn"}, produces = {"application/json;charset=UTF-8"})

public class OrderReturnController {
    @Autowired
    private OrderReturnService orderReturnService;

    @ApiOperation(httpMethod = "GET", value = "分页查询订单退款")
    @RequestMapping({"/pageOrderReturn"})
    public QueryResults<OrderReturnView> pageOrderReturn(Long userId,Long sellerUserId,Long orderId, int pageNum, int pageSize) {
        return this.orderReturnService.pageOrderReturn( userId, sellerUserId, orderId,  pageNum,  pageSize);
    }

    @ApiOperation(httpMethod = "GET", value = "分页查询订单退款（商家）")
    @RequestMapping({"/pageOrderReturnBySeller"})
    public QueryResults<OrderReturnView> pageOrderReturnBySeller(Long sellerUserId,int pageNum, int pageSize) {
        return this.orderReturnService.pageOrderReturnBySeller(sellerUserId,pageNum,pageSize);
    }

    @ApiOperation(httpMethod = "GET", value = "分页查询订单退款(会员用户)")
    @RequestMapping({"/pageOrderReturnByUser"})
    public QueryResults<OrderReturnByUserView> pageOrderReturnByUser(Long userId, int pageNum, int pageSize) {
        return this.orderReturnService.pageOrderReturnByUser(userId, pageNum,  pageSize);
    }

    @ApiOperation(httpMethod = "POST", value = "保存订单退款")
    @RequestMapping({"/saveOrderReturn"})
    public Result saveOrderReturn(Long orderItemId,String returnType,String cause,String remark,Set<Long> attachIds) {
        return this.orderReturnService.saveOrderReturn(orderItemId, returnType, cause, remark,attachIds);
    }

    @ApiOperation(httpMethod = "POST", value = "审核退款")
    @RequestMapping({"/checkOrderReturn"})
    public Result checkOrderReturn(String result,String remark,Set<Long> ids) {
        return this.orderReturnService.checkOrderReturn(result,remark,ids);
    }
    @ApiOperation(httpMethod = "GET", value = "删除订单退款")
    @ApiImplicitParam(name = "orderReturnId", value = "标识", required = true)
    @RequestMapping({"/deleteOrderReturn"})
    public Result deleteOrderReturn(Long orderReturnId) {
        return this.orderReturnService.delete(orderReturnId);
    }

    @ApiOperation(httpMethod = "GET", value = "订单退款详情")
    @ApiImplicitParam(name = "orderReturnId", value = "标识", required = true)
    @RequestMapping({"/detailOrderReturn"})
    public Result<OrderReturnDetailView> detailOrderReturn(Long orderReturnId) {
        return this.orderReturnService.detailOrderReturn(orderReturnId);
    }

    @ApiOperation(httpMethod = "POST", value = "微信退款售后订单商品回调", hidden = true)
    @RequestMapping({"/responseWeixinOrderItemRefundNotify/{configId}"})
    public String responseWeixinOrderItemRefundNotify(@PathVariable Long configId) {
        return this.orderReturnService.responseWeixinOrderItemRefundNotify(configId);
    }

    @ApiOperation(httpMethod = "POST", value = "微信退款售后订单回调", hidden = true)
    @RequestMapping({"/responseWeixinOrderRefundNotify/{configId}"})
    public String responseWeixinOrderRefundNotify(@PathVariable Long configId) {
        return this.orderReturnService.responseWeixinOrderRefundNotify(configId);
    }

}
